<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<link rel="icon" type="shortcut icon" th:href="@{/img/favicon.ico}" />
	<link rel="stylesheet" type="text/css" th:href="@{/css/bootstrap.min.css}" />
	<link rel="stylesheet" type="text/css" th:href="@{/css/global.css}" />
	<link rel="stylesheet" type="text/css" th:href="@{/css/letter.css}" />
	<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.3.0/font/bootstrap-icons.css">
	<title>郑在守护—私信详情</title>
	<style>
		/* 防诈骗横幅样式 */
		.anti-fraud-banner {
			background: rgb(18, 127, 249);
			color: white;
			padding: 8px;
			text-align: center;
			font-size: 0.9rem;
		}
		
		.anti-fraud-banner h4 {
			font-size: 1rem;
			margin-bottom: 4px;
		}
		
		.anti-fraud-banner p {
			font-size: 0.8rem;
			margin-bottom: 0;
		}
		
		/* 确保header不是深色背景 */
		header.bg-dark {
			background-color: white !important;
		}
		
		/* 导航栏样式 - 与index.html保持一致 */
		.navbar {
			background-color: white !important;
			box-shadow: 0 1px 3px rgba(0,0,0,0.1);
			height: 56px;
			padding: 0;
			border-radius: 4px;
			margin-top: 5px;
		}
		
		.navbar-brand {
			display: flex;
			align-items: center;
			padding: 0 16px;
			height: 56px;
			border-right: 1px solid #f0f0f0;
			font-weight: 600;
			color: #2196F3;
			transition: all 0.3s ease;
		}
		
		.navbar-brand:hover {
			background-color: rgba(33, 150, 243, 0.05);
		}
		
		.navbar-brand i {
			color: #2196F3;
			font-size: 20px;
			margin-right: 8px;
		}
		
		.navbar-brand span {
			color: #2196F3;
			font-size: 16px;
			font-weight: 600;
		}
		
		.navbar-nav {
			display: flex;
			align-items: center;
			height: 56px;
			padding: 0 12px;
		}
		
		.nav-item {
			height: 56px;
			margin: 0 2px;
		}
		
		.nav-link {
			display: flex !important;
			align-items: center;
			height: 56px;
			padding: 0 12px !important;
			color: #666 !important;
			position: relative;
			font-size: 13px;
			transition: all 0.3s ease;
		}
		
		.nav-link i {
			font-size: 16px;
			margin-right: 5px;
			transition: transform 0.2s ease;
			display: inline-block;
			vertical-align: middle;
		}
		
		.nav-link span {
			display: inline-block;
			vertical-align: middle;
		}
		
		.nav-link:hover {
			color: #2196F3 !important;
			background-color: rgba(33, 150, 243, 0.05);
		}
		
		.nav-link:hover i {
			transform: scale(1.1);
		}
		
		.nav-link.active {
			color: #2196F3 !important;
			font-weight: 500;
		}
		
		.nav-link.active:after {
			content: '';
			position: absolute;
			bottom: 0;
			left: 16px;
			right: 16px;
			height: 2px;
			background-color: #2196F3;
		}

		/* 修改通知徽章样式，使其成为红色圆圈白色数字 */
		.badge-danger {
			position: absolute;
			top: -5px;
			right: -5px;
			padding: 0.25rem 0.4rem;
			font-size: 0.75rem;
			font-weight: 700;
			color: #fff;
			background-color: #ff4d4f;
			border-radius: 50%;
			min-width: 18px;
			height: 18px;
			line-height: 1;
			text-align: center;
			display: flex;
			align-items: center;
			justify-content: center;
			box-shadow: 0 0 0 1px #fff;
		}

		/* 为导航项添加相对定位，以便正确放置通知徽章 */
		.nav-link.position-relative {
			position: relative;
		}
		
		.search-form {
			position: relative;
			margin-right: 12px;
		}
		
		.search-form input {
			width: 200px;
			height: 32px;
			padding: 0 32px 0 12px;
			border: 1px solid #e8e8e8;
			border-radius: 16px;
			background-color: #f5f5f5;
			font-size: 13px;
			transition: all 0.3s ease;
		}
		
		.search-form input:focus {
			width: 240px;
			border-color: #2196F3;
			box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.2);
			outline: none;
		}
		
		.search-form .serach-btn {
			position: absolute;
			right: 4px;
			top: 4px;
			width: 24px;
			height: 24px;
			font-size: 14px;
			background-color: transparent;
			border: none;
			color: #2196F3;
			cursor: pointer;
			transition: all 0.2s ease;
		}
		
		.search-form .serach-btn:hover {
			transform: scale(1.1);
			color: #1976D2;
		}
		
		.user-info {
			height: 56px;
			border-left: 1px solid #f0f0f0;
			padding-left: 16px;
			transition: all 0.3s ease;
		}
		
		.user-info:hover {
			background-color: rgba(33, 150, 243, 0.05);
		}
		
		.user-avatar {
			width: 32px;
			height: 32px;
			border-radius: 50%;
			margin-right: 6px;
			border: 2px solid rgba(33, 150, 243, 0.2);
			transition: all 0.3s ease;
		}
		
		.user-info:hover .user-avatar {
			border-color: rgba(33, 150, 243, 0.5);
		}
		
		/* 聊天界面样式 */
		.chat-container {
			background-color: #f8f9fa;
			border-radius: 8px;
			box-shadow: 0 2px 10px rgba(0,0,0,0.05);
			padding: 20px;
			margin-top: 20px;
		}
		
		.chat-header {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding-bottom: 15px;
			border-bottom: 1px solid #e9ecef;
			margin-bottom: 20px;
		}
		
		.chat-title {
			display: flex;
			align-items: center;
		}
		
		.chat-title .square {
			display: inline-block;
			width: 10px;
			height: 10px;
			background-color: #2196F3;
			margin-right: 10px;
		}
		
		.chat-actions {
			display: flex;
			gap: 10px;
		}
		
		/* 消息样式 */
		.message-list {
			display: flex;
			flex-direction: column-reverse;  /* 反转方向，使最新消息在底部 */
			gap: 15px;
			height: 500px;  /* 设置固定高度 */
			overflow-y: auto;  /* 允许垂直滚动 */
			padding: 20px 0;
		}
		
		/* 确保消息项的顺序正确 */
		.message-item {
			display: flex;
			margin-bottom: 15px;
			order: 1;  /* 确保消息按正确顺序显示 */
		}
		
		.message-avatar {
			width: 40px;
			height: 40px;
			border-radius: 50%;
			margin-right: 15px;
			border: 2px solid rgba(33, 150, 243, 0.2);
		}
		
		.message-content {
			max-width: 70%;
			border-radius: 18px;
			padding: 12px 16px;
			position: relative;
			box-shadow: 0 1px 2px rgba(0,0,0,0.1);
		}
		
		.message-sender {
			background-color: #e3f2fd;
			border-top-left-radius: 4px;
			margin-right: auto;
		}
		
		.message-receiver {
			background-color: #2196F3;
			color: white;
			border-top-right-radius: 4px;
			margin-left: auto;
		}
		
		.message-info {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 5px;
		}
		
		.message-username {
			font-weight: 500;
			font-size: 14px;
		}
		
		.message-time {
			font-size: 12px;
			color: #6c757d;
		}
		
		.message-receiver .message-time {
			color: rgba(255,255,255,0.8);
		}
		
		.message-text {
			word-break: break-word;
		}
		
		/* 发送消息表单 */
		.send-message-form {
			display: flex;
			margin-top: 20px;
			background-color: white;
			border-radius: 24px;
			padding: 8px;
			box-shadow: 0 1px 3px rgba(0,0,0,0.1);
		}
		
		.message-input {
			flex-grow: 1;
			border: none;
			padding: 8px 16px;
			border-radius: 24px;
			outline: none;
		}
		
		.send-button {
			background-color: #2196F3;
			color: white;
			border: none;
			border-radius: 50%;
			width: 40px;
			height: 40px;
			display: flex;
			align-items: center;
			justify-content: center;
			cursor: pointer;
			transition: all 0.2s;
		}
		
		.send-button:hover {
			background-color: #1976D2;
			transform: scale(1.05);
		}
		
		/* 模态框样式优化 */
		.modal-content {
			border-radius: 8px;
			border: none;
		}
		
		.modal-header {
			background-color: #f8f9fa;
			border-bottom: 1px solid #e9ecef;
		}
		
		.modal-footer {
			background-color: #f8f9fa;
			border-top: 1px solid #e9ecef;
		}
	</style>
</head>
<body>
	<div class="nk-container">
		<!-- 防诈骗横幅 -->
		<div class="anti-fraud-banner">
			<div class="container">
				<h4><i class="bi bi-shield-check"></i> 提高警惕，防范诈骗</h4>
				<p class="mb-0">共建平安校园，远离电信诈骗</p>
			</div>
		</div>
		
		<!-- 确保导航栏水平显示 -->
		<style>
		    /* 确保导航栏水平显示 */
		    .navbar-nav.mr-auto {
		        flex-wrap: nowrap;
		        overflow-x: visible;
		        width: auto;
		        margin-right: 0 !important; /* 移除右边距 */
		    }
		    
		    /* 确保导航栏容器宽度合适 */
		    .navbar > .container {
		        display: flex;
		        align-items: center;
		        justify-content: space-between;
		        padding: 0 10px; /* 调整内边距 */
		        max-width: 100%; /* 确保容器可以占满宽度 */
		    }
		    
		    /* 调整折叠导航栏 */
		    .collapse.navbar-collapse {
		        display: flex !important;
		        flex-basis: auto;
		        justify-content: space-between;
		    }
		    
		    /* 确保导航项目在一行显示 */
		    .navbar-nav {
		        flex-direction: row !important;
		        flex-wrap: nowrap !important;
		    }
		    
		    /* 调整导航项目间距 */
		    .navbar-nav .nav-item {
		        white-space: nowrap;
		        margin: 0 2px; /* 恢复原始间距 */
		    }
		    
		    /* 调整搜索框和用户信息的位置 */
		    .navbar-right {
		        display: flex;
		        align-items: center;
		        margin-left: auto;
		    }
		</style>
		
		<!-- 头部 -->
		<header class="bg-white sticky-top" th:replace="index::header"></header>

		<!-- 内容 -->
		<div class="main">
			<div class="container">
				<div class="chat-container">
					<div class="chat-header">
						<div class="chat-title">
							<b class="square"></b>
							<h5 class="mb-0">与 <a class="text-primary" th:utext="${target.username}" th:href="@{|/user/profile/${target.id}|}"></a> 的对话</h5>
						</div>
						<div class="chat-actions">
							<button type="button" class="btn btn-outline-secondary btn-sm" onclick="back();">
								<i class="bi bi-arrow-left"></i> 返回
							</button>
							<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#sendModal">
								<i class="bi bi-chat-left-text"></i> 发送私信
							</button>
						</div>
					</div>
					
					<!-- 私信列表 -->
					<div class="message-list">
						<div class="message-item" th:each="map:${letters}" th:classappend="${map.letter.fromId==loginUser.id ? 'flex-row-reverse' : ''}">
							<a th:href="@{|/user/profile/${map.fromUser.id}|}">
								<img th:src="${map.fromUser.headerUrl}" class="message-avatar" alt="用户头像">
							</a>
							<div class="message-content" th:classappend="${map.letter.fromId==loginUser.id ? 'message-receiver' : 'message-sender'}">
								<div class="message-info">
									<span class="message-username" th:utext="${map.fromUser.username}"></span>
									<span class="message-time" th:text="${#dates.format(map.letter.createTime, 'yyyy-MM-dd HH:mm:ss')}"></span>
								</div>
								<div class="message-text" th:utext="${map.letter.content}"></div>
							</div>
						</div>
					</div>
					
					<!-- 快速回复表单 -->
					<div class="send-message-form">
						<input type="text" class="message-input" placeholder="输入消息..." id="quickReplyInput">
						<button class="send-button" id="quickReplyBtn">
							<i class="bi bi-send"></i>
						</button>
					</div>
					
					<!-- 分页 -->
					<nav class="mt-4" th:replace="index::pagination"></nav>
				</div>
			</div>
		</div>

		<!-- 弹出框 -->
		<div class="modal fade" id="sendModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
			<div class="modal-dialog modal-lg" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<h5 class="modal-title" id="exampleModalLabel">发送私信</h5>
						<button type="button" class="close" data-dismiss="modal" aria-label="Close">
							<span aria-hidden="true">&times;</span>
						</button>
					</div>
					<div class="modal-body">
						<form>
							<div class="form-group">
								<label for="recipient-name" class="col-form-label">发给：</label>
								<input type="text" class="form-control" id="recipient-name" th:value="${target.username}" readonly>
							</div>
							<div class="form-group">
								<label for="message-text" class="col-form-label">内容：</label>
								<textarea class="form-control" id="message-text" rows="10" placeholder="请输入私信内容..."></textarea>
							</div>
						</form>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
						<button type="button" class="btn btn-primary" id="sendBtn">发送</button>
					</div>
				</div>
			</div>
		</div>
		
		<!-- 提示框 -->
		<div class="modal fade" id="hintModal" tabindex="-1" role="dialog" aria-labelledby="hintModalLabel" aria-hidden="true">
			<div class="modal-dialog modal-lg" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<h5 class="modal-title" id="hintModalLabel">提示</h5>
						<button type="button" class="close" data-dismiss="modal" aria-label="Close">
							<span aria-hidden="true">&times;</span>
						</button>
					</div>
					<div class="modal-body" id="hintBody">
						发送完毕!
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
					</div>
				</div>
			</div>
		</div>

		<!-- 尾部 -->
		<footer class="bg-dark" th:replace="index::footer"></footer>
	</div>

	<script th:src="@{/js/jquery-3.1.0.min.js}"></script>
	<script th:src="@{/js/popper.min.js}"></script>
	<script th:src="@{/js/bootstrap.min.js}"></script>
	<script th:src="@{/js/global.js}"></script>
	<script th:src="@{/js/letter.js}"></script>
	<script>
		function back() {
			location.href = CONTEXT_PATH + "/letter/list";
		}
		
		$(function() {
			// 快速回复功能
			$("#quickReplyBtn").click(function() {
				var content = $("#quickReplyInput").val();
				if(content) {
					$("#message-text").val(content);
					$("#sendBtn").click();
					$("#quickReplyInput").val('');
				}
			});
			
			// 回车发送
			$("#quickReplyInput").keydown(function(e) {
				if(e.keyCode == 13) {
					e.preventDefault();
					$("#quickReplyBtn").click();
				}
			});
			
			// 初始化时滚动到底部
			var messageList = $(".message-list");
			messageList.scrollTop(messageList[0].scrollHeight);
			
			// 发送消息后自动滚动到底部
			$("#sendBtn").click(function() {
				setTimeout(function() {
					messageList.scrollTop(messageList[0].scrollHeight);
				}, 100);
			});
		});
	</script>
</body>
</html>
